home *** CD-ROM | disk | FTP | other *** search
-
- extern Pixmap pointer_pmap; // aus Modul graph.C ...
- extern int pointer_off_x, pointer_off_y; // dto.
-
- #ifndef _cursor_h
- # include "cursor.h"
- #endif
-
- int PBall::instance_count = 0;
- int PBall::pwidth = 0;
- int PBall::pheight = 0;
- Pixmap PBall::pmap = 0;
- GC PBall::gc_bit = 0;
-
- PBall::PBall( PBallType type, char *disp_name ) :
- PBallTop( type )
- {
- //
- // Remote Display ÷ffnen
- //
- rem_dpy = XOpenDisplay( disp_name );
- if (!rem_dpy) {
- fprintf( stderr, "ERROR: can't open display '%s'.\n", disp_name );
- exit(0);
- }
- scr=DefaultScreen(rem_dpy);
- //
- // Cursor ⁿberdefinieren
- //
- Cursor cursor;
- Pixmap pixmap;
- XColor col1;
- pixmap = XCreateBitmapFromData(rem_dpy,
- RootWindow( rem_dpy, scr ),
- cursor_bits, cursor_width, cursor_height );
- XParseColor(rem_dpy,DefaultColormap(rem_dpy,scr), "black", &col1 );
- cursor = XCreatePixmapCursor( rem_dpy, pixmap, pixmap, &col1, &col1,
- cursor_x_hot, cursor_y_hot );
- XGrabPointer( rem_dpy, RootWindow( rem_dpy, scr ),
- False, (unsigned)(ButtonPressMask|ButtonReleaseMask|PointerMotionMask),
- GrabModeAsync, GrabModeAsync, None, cursor, CurrentTime );
-
- //
- // Transformation festlegen
- //
- w2n_x = DisplayWidth( rem_dpy,scr)/world_x;
- w2n_y = DisplayHeight(rem_dpy,scr)/world_y;
- //
- // Pointer auf Bildschirm initialisieren.
- //
- x_old = -20; // ausserhalb des Bildschirms (wegen erstem CopyArea)
- y_old = -20;
-
- XFreePixmap( rem_dpy, pixmap );
- XFreeCursor( rem_dpy, cursor );
-
-
- if (!instance_count++) {
- pwidth = 30;
- pheight = 30;
- pmap = XCreatePixmap(dpy,win,pwidth,pheight,1);
- gc_bit = XCreateGC(dpy,pmap,0,0);
- XSetState(dpy,gc_bit,1,0,GXxor,1);
- }
- }
-
- PBall::~PBall() {
- if (!--instance_count) {
- XFreePixmap(dpy,pmap);
- XFreeGC(dpy,gc_bit);
- }
- //
- // Pointer vom Bildschirm l÷schen
- //
- XCopyArea( dpy, pointer_pmap, win, gc_cursor, 0, 0, 16, 16,
- x_old-pointer_off_x, y_old-pointer_off_y );
-
- XSync( rem_dpy, 0 );
- XCloseDisplay( rem_dpy );
- }
-
- void PBall::Update() {
- XEvent event;
-
- while (XEventsQueued( rem_dpy, QueuedAfterFlush )) {
- XNextEvent( rem_dpy, &event );
- switch( event.xany.type ) {
- case MotionNotify:
- while( XCheckMaskEvent( rem_dpy, PointerMotionMask, &event ));
- PointerMoveTo(Vec2(Real(event.xmotion.x)/w2n_x,
- Real(event.xmotion.y)/w2n_y));
- break;
- case ButtonPress:
- Press( event.xbutton.button );
- break; // case ButtonPress
-
- case ButtonRelease:
- Release( event.xbutton.button );
- } // switch(event.type)
- }
-
- PBallTop::Update();
- }
-
-
- void PBall::Warp( const Vec2 &dest ) {
- XEvent event;
-
- XWarpPointer( rem_dpy, None, RootWindow( rem_dpy, scr ),
- 0,0,0,0 ,
- (int)(dest.X()*w2n_x),
- (int)(dest.Y()*w2n_y) );
-
- if (mode&UsingTool) MoveAimingTool();
-
- XSync( rem_dpy, 0 );
- while( XCheckMaskEvent( rem_dpy, PointerMotionMask, &event ));
- }
-
-
- void PBall::RedrawPointer() {
- XCopyArea( dpy, pointer_pmap, win, gc_cursor, 0, 0, 16, 16,
- x_old-pointer_off_x, y_old-pointer_off_y );
- }
-
- void PBall::SetPointer( int x, int y ) {
- XCopyArea( dpy, pointer_pmap, win, gc_cursor, 0, 0, 16, 16,
- x_old-pointer_off_x, y_old-pointer_off_y );
- x_old = x;
- y_old = y;
- // RedrawPointer:
- XCopyArea( dpy, pointer_pmap, win, gc_cursor, 0, 0, 16, 16,
- x_old-pointer_off_x, y_old-pointer_off_y );
- }
-
-
- // ------------------------------------------------------------
-
- #ifndef XPix
- # define XPix(x) ((int)((x)*w2n))
- # define YPix(y) ((int)((y)*w2n))
- # define Pix(r) ((int)((r)*w2n))
- #endif
-
- void PBall::DrawQueue() {
- if (valid_queue_position) {
- XPoint p[3];
-
- p[0].x = XPix(q_end_s.X());
- p[0].y = YPix(q_end_s.Y());
- p[1].x = XPix(q_s1_s.X());
- p[1].y = YPix(q_s1_s.Y());
- p[2].x = XPix(q_s2_s.X());
- p[2].y = YPix(q_s2_s.Y());
- XFillPolygon(dpy,win,gc_current,p,3,0,0);
- }
- }
-
- void PBall::StartQueue(const Vec2 &end, const Vec2 &s1, const Vec2 &s2) {
- q_end_s = end;
- q_s1_s = s1;
- q_s2_s = s2;
- valid_queue_position = 1;
- DrawQueue();
- }
-
- void PBall::MoveQueue(const Vec2 &end, const Vec2 &s1, const Vec2 &s2) {
- XPoint p[6];
- int i;
-
- p[0].x = XPix(q_end_s.X());
- p[0].y = YPix(q_end_s.Y());
- p[1].x = XPix(q_s1_s.X());
- p[1].y = YPix(q_s1_s.Y());
- p[2].x = XPix(q_s2_s.X());
- p[2].y = YPix(q_s2_s.Y());
-
- q_end_s = end;
- q_s1_s = s1;
- q_s2_s = s2;
- p[3].x = XPix(q_end_s.X());
- p[3].y = YPix(q_end_s.Y());
- p[4].x = XPix(q_s1_s.X());
- p[4].y = YPix(q_s1_s.Y());
- p[5].x = XPix(q_s2_s.X());
- p[5].y = YPix(q_s2_s.Y());
-
- valid_queue_position = 1;
-
- int min_x = p[0].x;
- int max_x = p[0].x;
- int min_y = p[0].y;
- int max_y = p[0].y;
-
- // Minimum suchen
- for (i=1;i<sizeof(p)/sizeof(XPoint);i++) {
- if (p[i].x < min_x) min_x = p[i].x;
- if (p[i].x > max_x) max_x = p[i].x;
- if (p[i].y < min_y) min_y = p[i].y;
- if (p[i].y > max_y) max_y = p[i].y;
- }
-
- // Punkte nun relativ zur Bitmap
- for (i=0;i<sizeof(p)/sizeof(XPoint);i++) {
- p[i].x -= min_x;
- p[i].y -= min_y;
- }
-
- int width = max_x - min_x;
- int height = max_y - min_y;
-
- // ggf. vergroesserte Pixmap anlegen
- if (width>pwidth||height>pheight) {
- XFreePixmap(dpy,pmap);
- if (width>pwidth) pwidth =width +10;
- if (height>pheight) pheight=height+10;
- pmap = XCreatePixmap(dpy,win,pwidth,pheight,1);
- }
-
- // Pixmap aufbauen und ins Fenster verknuepfen
- XSetFunction(dpy,gc_bit,GXclear);
- XFillRectangle(dpy,pmap,gc_bit,0,0,width,height);
- XSetFunction(dpy,gc_bit,GXxor);
- XFillPolygon(dpy,pmap,gc_bit,&p[0],3,0,0);
- XFillPolygon(dpy,pmap,gc_bit,&p[3],3,0,0);
- XCopyPlane(dpy,pmap,win,gc_current,0,0,width,height,min_x,min_y,1);
- }
-
- void PBall::EndQueue() {
- DrawQueue();
- valid_queue_position = 0;
- }
-
-